<?php
namespace app\index\service;

use app\index\model\BidModel;
use app\index\model\BidPoolModel;
use think\Db;

class BidService extends CommonService
{
    public function get_bid_state(){
        return [
            1=>'在投',
            3=>'中标',
            6=>'未中标',
        ];
    }

    public function get_bid_state_name_wen($data){
        $name = '';
        if($data['status'] == 1){
            if($data['state'] == 1){
                if($data['isqi'] > 0){
                    $name = '在投[放弃]';
                }else{
                    $name = '在投';
                }
            }
            if($data['state'] == 3){
                if($data['isqi'] > 0){
                    $name = '中标[放弃]';
                }else{
                    $name = '中标';
                }
            }
            if($data['state'] == 6){
                if($data['isqi'] > 0){
                    $name = '未中标[放弃]';
                }else{
                    $name = '未中标';
                }
            }
        }
        return $name;
    }

    public function get_bid_state_name_tag($data){
        $name = '';
        if($data['status'] == 1){
            if($data['state'] == 1){
                if($data['isqi'] > 0){
                    $name = '<span class="">在投</span><span class="colorhong">[放弃]</span>';
                }else{
                    $name = '<span class="">在投</span>';
                }
            }
            if($data['state'] == 3){
                if($data['isqi'] > 0){
                    $name = '<span class="">中标</span><span class="colorhong">[放弃]</span>';
                }else{
                    $name = '<span class="">中标</span>';
                }
            }
            if($data['state'] == 6){
                if($data['isqi'] > 0){
                    $name = '<span class="">未中标</span><span class="colorhong">[放弃]</span>';
                }else{
                    $name = '<span class="">未中标</span>';
                }
            }
        }
        return $name;
    }

    public function get_bid_tou_kaitype(){
        return ['现场开标', '远程开标'];
    }

    public function get_bid_kai_guo(){
        return [
            3=>'中标',
            6=>'未中标',
        ];
    }

    public function check_bid_pool_name($name, $id=0){
        return !!BidPoolModel::where(['comid'=>$this->userinfo['comid'],'name'=>$name,'deleted_user'=>0,'isturn'=>1])
            ->where('status','in',[0,1])->where('id','neq', $id)->find();
    }

    public function check_bid_name($name, $id=0){
        return !!BidModel::where(['comid'=>$this->userinfo['comid'],'name'=>$name,'deleted_user'=>0,'isturn'=>1])
            ->where('status','in',[0,1])->where('id','neq', $id)->find();
    }


    public function get_user_bid(){
        $where = Db::raw("created_user=".$this->userinfo['id']." or touer=".$this->userinfo['id']);
        $arr = BidModel::where(['comid'=>$this->userinfo['comid'],'deleted_user'=>0,'isturn'=>1,'status'=>1])
            ->where($where)
            ->column('id');
        return $arr;
    }









}
